home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
pc_board
/
sendcom.zip
/
SENDCOM.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-14
|
3KB
|
143 lines
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys\stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <dos.h>
#include <string.h>
#include "pcbsys.h"
#define CR "\n\r"
#define rs232 0x14
#define writech 1
#define mask 0x7f
#define YES 1
#define NO 0
#define DATA_READY 0
#define OVERRUN 0x1
#define PARITY 0x2
#define FRAMING 0x8
#define BRK 0x10
#define HOLDEMPTY 0x20
#define SHIFTEMPTY 0x40
#define FAILED 0x80
union REGS regs;
int LOCAL;
int COMPORT,mode,fileflag;
char commandline[255];
char filter[80];
extern int ANSI;
char *pcb_printf(char *);
void xmit(char);
void sendstr(char *);
void CRLF(int);
/*::::::::::::::::::::::::[ DISPLAY SECURITY FILE ]::::::::::::::::::::*/
void display_file(char *filename){
FILE *fp;
char buffer[85];
int bufflen=80;
if((fp=fopen(filename,"r"))==NULL){
strcpy(commandline,filename);
strcat(commandline," was not found!");
sendstr(commandline);
exit(1);}
CRLF(1);
while((fgets(buffer,bufflen,fp))!=NULL){
if(!strcmp(filter,"")){
sendstr(buffer);
xmit('\r');}
else
if(strstr(buffer,filter)){
sendstr(buffer);
xmit('\r');}
}
fclose(fp); }
/*:::::::::::::::::::::::[ Send CR LF ]:::::::::::::::::::::::::::*/
void CRLF(int cnt){
int i;
for (i=0;i<cnt;i++){
xmit('\n');
xmit('\r');
printf("\n"); }}
/*::::::::::::::[ SEND ONE CHARACTER TO SERIAL PORT ]::::::::::::::*/
void xmit(char ch){
int flag;
if(LOCAL==YES) return;
regs.h.ah = writech;
regs.x.dx = COMPORT;
regs.h.al = ch;
int86(rs232,®s,®s);
flag =(regs.h.ah&FAILED);
if (flag!=0){
printf(" COM%d failed! ",COMPORT+1);
exit(1);}
}
/*::::::::::::::::::[ Send string to Com ]:::::::::::::::::::::::*/
void xmit_str(char *s){
while(*s != '\0'){
xmit(*s);
s++; }}
/*:::::::::::::::::::[ Send string to COM or CON ]::::::::::::::::::*/
void sendstr(char *s){
char *str;
str=pcb_printf(s);
xmit_str(str);
}
/*:::::::::::::::::::[ Get command line ]:::::::::::::::::::::::::::*/
void getcline(int cnt,char *argarray[]){
int i;
memset(commandline,'\0',255);
for(i=1;i<cnt;i++){
if(!strcmp(strupr(argarray[i]),"/F")){
fileflag=1;
strcpy(commandline,argarray[i+1]);
if(cnt>4) strcpy(filter,argarray[i+2]);
else strcpy(filter,"");
return; }
if(!strcmp(argarray[i],"CR"))
strcat(commandline,CR);
else {
strcat(commandline,argarray[i]);
strcat(commandline," "); }}}
main(int argc,char *argv[]){
mode=0;
if((pcbs.getdata(pcbs))==-1){
cout << "\nCouldn't read PCBOARD.SYS\n\n";
exit(1);
}
char gm=pcbs.get_graphics();
switch (gm){
case 'Y':ANSI=YES;break;
case 'N':
case '7':ANSI=NO;break;
}
if((strcmp(pcbs.get_connectspeed(),"Local"))==0)
LOCAL=YES;
else LOCAL=NO;
COMPORT=pcbs.get_comport()-'1';
getcline(argc,argv);
if (fileflag==1)
display_file(commandline);
else
sendstr(commandline);
}